import React, { Component } from 'react';
import { Navigate, useLocation } from 'react-router-dom';
import PageNotFound from '@/components/PageNotFound';

class ErrorBoundary extends Component {
  constructor(props) {
    super(props);
    this.state = { error: null };
  }

  static getDerivedStateFromError(error) {
    return { error };
  }

  componentDidCatch(error, errorInfo) {
    console.error('Error caught by ErrorBoundary:', error, errorInfo);
  }

  render() {
    if (this.state.error) {
      return <PageNotFound />;
    }

    return this.props.children;
  }
}

export default ErrorBoundary;